import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { DrawHistory } from './draw-history.entity';
import { RestaurantMark } from './restaurant-mark.entity';

export type FrequencyRule = 'daily' | 'weekly' | 'monthly';

@Entity('restaurants')
export class Restaurant {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'varchar', length: 255 })
  name: string;

  @Column({ type: 'varchar', length: 100 })
  category: string;

  @Column({
    type: 'enum',
    enum: ['daily', 'weekly', 'monthly'],
    default: 'daily',
  })
  frequency_rule: FrequencyRule;

  @Column({ type: 'text', nullable: true })
  notes?: string;

  @CreateDateColumn({ type: 'timestamp' })
  created_at: Date;

  @UpdateDateColumn({ type: 'timestamp' })
  updated_at: Date;

  // 关联关系
  @OneToMany(() => DrawHistory, (drawHistory) => drawHistory.restaurant)
  drawHistories: DrawHistory[];

  @OneToMany(() => RestaurantMark, (mark) => mark.restaurant)
  marks: RestaurantMark[];
}
